package com.sinosoft.cloud.access.handler;

import com.sinosoft.cloud.access.crypto.CryptoBean;
import com.sinosoft.cloud.access.net.MessageObject;
import io.netty.channel.ChannelHandlerContext;

/**
 * cloud-netty
 *
 * @title: cloud-netty
 * @package: com.sinosoft.cloud.access.handler
 * @author: yangming
 * @date: 2017/12/2 下午4:56
 */
public class CryptoHandler extends AbstractHandler {
    @Override
    MessageObject dealMessage(ChannelHandlerContext ctx, MessageObject messageObject) {
        CryptoBean cryptoBean = getCryptoBean();
        if (cryptoBean != null) {
            String currentMsg = messageObject.getOriginalMsg();
            currentMsg = cryptoBean.decryt(currentMsg);
            if (currentMsg != null) {
                /*存储解密后的非标准报文*/
                messageObject.setDecryptMsg(currentMsg.trim());
            }
        }
        messageObject.setNext(MessageObject.Type.fireChannelRead);
        logger.info("接收到解密消息为：" + messageObject.getDecryptMsg());
        return messageObject;
    }
}
